<template>
    <div>
        <a-form :form="form">
            <slot name="form" :formItems="formItems" :form="form" :changeItem="changeItem"></slot>
        </a-form>
        <LiconSelect ref="liconSelect"></LiconSelect>
    </div>
</template>
<script>

import LiconSelect from '@/components/lt/LIconSelect.vue'

export default {
    name:'LCustomForm',
    components:{LiconSelect},
    props:{
        mostColumns:{
            type:Number,
            default:1
        },
        formItems:{
           type:Object,
           default:()=>{}
        },
   
        onChange:Function,
        onClick:Function,
    },
    data(){
        return{
            form:{},
            changeItem:{},//表单中当前改变值的组件，键值对
            that:this
        }
    },
   
    created(){
        this.form=this.$form.createForm(this,{onValuesChange:this.valueChange}) 
    },
    methods:{
        getForm(){
            return this.form
        },
        valueChange(props, values){
            this.changeItem = values
            this.changeEventHandler()
        },
        changeEventHandler(){
            if(this.changeItem){
                let item = JSON.parse(JSON.stringify(this.changeItem))
                if(Object.getOwnPropertyNames(item).length==1){
                    this.$emit("onChange",item)
                }
            }
        },
        clickEventHandler(field,form){
            this.$emit("onClick",field,form)
        }
      
    }
}
</script>